﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZDSoft.UPMS.Model.SystemPart;
using ZDSoft.UPMS.Core;
using ZDSoft.UPMS.Service.SystemPart;
using ZDSoft.UPMS.Web.App;

namespace ZDSoft.UPMS.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Top()
        {
            User  User= AppHelper.LoginedUser;
            IList<User> list = new List<User>();
            list.Add(User);
            ViewData["User"] = App.AppHelper.LoginedUser.Name;
            return View(list);
        }

        public string logOff()
        {
            AppHelper.LoginedUser = null;
            return "true";
        }

        public ActionResult Left()
        {

      
            IList<SystemFunction> list = AppHelper.Privileges;
            string str = GetZtree(list);
            TempData["ZTree"] = str;
            return View(AppHelper.Privileges);
        }

        public ActionResult Content()
        {
            return View();
        }
        public string GetZtree(IList<SystemFunction> list)
        {
            //{ id: 1, pId: 0, name: "教师工作评价指标", url: "/test/CreateTest", target: "testIframe", open: false },
            string str = "";
            foreach (SystemFunction systemFunction in list)
            {
                if (systemFunction.Parent == null)
                {
                    str += "{id:" + systemFunction.ID + ",pId:0" + ",name:\"" + systemFunction.Name + "\",},";
                }
                else
                {
                    str += "{id:" + systemFunction.ID + ",pId:" + systemFunction.Parent.ID + ",name:\"" + systemFunction.Name + "\",url: \"/" + systemFunction.ControllerName + "/" + systemFunction.ActionName + "\",target:\"I2\"},";

                }
            }
            return str;
        }
    }
}
